package com.tlxch.server.teacher.impl;

import com.tlxch.mapper.TAlertMapper;
import com.tlxch.mapper.TGradewarnreportMapper;
import com.tlxch.pojo.TAlert;
import com.tlxch.pojo.TGradewarnreport;
import com.tlxch.server.teacher.TGradewarnreportService;
import com.tlxch.websocket.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Service
public class TGradewarnreportServiceImpl implements TGradewarnreportService {
    @Autowired
    TGradewarnreportMapper tGradewarnreportMapper;
    @Autowired
    TAlertMapper tAlertMapper;
    @Autowired
    WebSocketServer webSocketServer;

    @Transactional
    public void add(TGradewarnreport tGradewarnreport) {
        TAlert tAlert = new TAlert();
        tAlert.setTaId(tGradewarnreport.getTgarTaid());
        tAlert.setTaStatus(2);
        tAlertMapper.updateKey(tAlert);
        String message = "{\"msg\":\"" +"您有一条新的成绩预警报告，请及时查看！\"}";
        webSocketServer.sendToClient(message,tGradewarnreport.getTgarSid());
        tGradewarnreport.setTgarCreatetime(LocalDateTime.now());
        tGradewarnreportMapper.insert(tGradewarnreport);
    }
}
